package com.example.liwushuo.adapter;

import java.util.List;

import com.example.liwushuo.BaseApp;
import com.example.liwushuo.R;
import com.example.liwushuo.bean.Channel_groups;
import com.example.liwushuo.bean.Channels;
import com.example.liwushuo.bean.Collections;
import com.example.liwushuo.bean.Posts;
import com.lidroid.xutils.BitmapUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HorTopAllAdapter extends BaseAdapter {

	private List<Collections> list;
	private LayoutInflater inflater;
	private Context context;

	private BitmapUtils bitmapUtils;
	public HorTopAllAdapter(List<Collections> list, Context context) {
		this.list = list;
		this.context = context;
		inflater = LayoutInflater.from(context);
		bitmapUtils = new BitmapUtils(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list != null && list.size() > 0 ? list.get(position) : 0;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.top_all_item, null);
			holder = new ViewHolder();
		holder.imageView=(ImageView) convertView.findViewById(R.id.topall_cover_image_url);
			holder.title = (TextView) convertView.findViewById(R.id.topall_title);
			holder.subtitle = (TextView) convertView
					.findViewById(R.id.topall_subtitle);
			convertView.setTag(holder);
		} else {

			holder = (ViewHolder) convertView.getTag();
		}
		bitmapUtils.display(holder.imageView, list.get(position).getCover_image_url());
	
		holder.title.setText(list.get(position).getTitle());
		holder.subtitle.setText(list.get(position).getSubtitle());
		return convertView;

	}

	private static class ViewHolder {
		ImageView imageView;
		TextView subtitle, title;

	}
}
